<?php

/**
 * Class 字段元素添加
 */
class FieldItemAdd{

    /**
     * Notes: 获取字段信息
     * User: ZhuHaili
     */
    static public function setItems($fieldsParam, $essayInfo = array()){
        // 初始值
        $result = array('html'=>'','style'=>'');
        // 验证参数
        $r = self::judgeParams($fieldsParam, $essayInfo);
        if(!$r){return $result;}
        // 遍历字段
        foreach($fieldsParam as $k=>$v){
            // 类型无定义放弃此次循环
            if(!isset($v['fieldtype'])){continue;}
            // 根据类型匹配对应的数据
            $fun = self::setFun($v['fieldtype']);
            $request = self::$fun($v, $essayInfo);
            $result['html'] .= $request['html'];
            $result['style'] .= $request['style'];
        }
        return $result;
    }

    /**
     * Notes:参数验证
     */
    static private function judgeParams($fieldsParam){
        if(!$fieldsParam){return false;}
        if(!is_array($fieldsParam)){return false;}
        if(!isset($fieldsParam[0])){return false;}
        $mustParam = array(
            'fieldname'=>'字段名称','fieldcode'=>'字段标识',
            'fieldval'=>'默认值','fieldtype'=>'字段类型','fieldrule'=>'字段规则','fieldrule2'=>'其他规则',
            'showwidth'=>'控件的宽','showheight'=>'控件的高',
            'fieldhint'=>'字段提示','fielddesc'=>'字段提示', 'banflag'=>'禁用标识'
        );
        foreach($mustParam as $k=>$v){
            if(!isset($fieldsParam[0][$k]) && $fieldsParam[0][$k] !== null){
                return false;
            }
        }
        return true;
    }

    /**
     * Notes: 根据字段类型获取执行的方法
     * User: ZhuHaili
     */
    static private function setFun($fileType){
        $funConfig = array(
            '1' => 'itemText',
            '2' => 'itemRichText',
            '3' => 'itemInt',
            '4' => 'itemMoney',
            '5' => 'itemPassword',
            '6' => 'itemIdCode',
            '7' => 'itemDatetime',
            '8' => 'itemDistrict',
            '9' => 'itemColor',
            '10' => 'itemSelect',
            '11' => 'itemRadio',
            '12' => 'itemCheckbox',
            '13' => 'itemPic',
            '14' => 'itemPicMore',
            '15' => 'itemFile',
            '16' => 'itemFileMore',
            '17' => 'itemImgCut',
            '20' => 'itemFieldTmpl',
        );
        return isset($funConfig[$fileType]) ? $funConfig[$fileType] : 'itemNull';
    }

    /**
     * Notes: 标题换行符
     * User: ZhuHaili
     */
    static private function itemTitleBr($showHeight){
        $br = '<br>';
        if(intval($showHeight) > 30){
            for($i = 0; $i < intval(ceil(($showHeight/25))); $i++){
                $br .= '<br>';
            }
        }
        return $br;
    }

    /**
     * Notes: 控件大小
     * User: ZhuHaili
     */
    static private function itemSize($showwidth, $showheight){
        $styleW = intval($showwidth) ? 'width:'.$showwidth.'px;' : '';
        $styleH = intval($showheight) ? 'height:'.$showheight.'px;' : '';
        return $styleW.$styleH;
    }

    /**
     * Notes: 控件样式
     * User: ZhuHaili
     */
    static private function itemStyle($style){
        return 'style="'.$style.'"';
    }

    /**
     * Notes: time13
     * User: ZhuHaili
     */
    static private function time13(){
        list($t1, $t2) = explode(' ', microtime());
        return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
    }

    /**
     * Notes: codeStr
     * User: ZhuHaili
     */
    static private function codeStr($fixStr){
        return $fixStr.self::time13().rand(100,999);
    }

    /**
     * Notes: 文本字段
     * User: ZhuHaili
     */
    static private function itemText($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        if($fieldsInfo['banflag'] == '1'){
            $styleCSS = 'display:inline-block;width:280px;height:20px;border:1px solid #ddd;padding: 5px 10px;line-height:20px;background: #dfdfdf;';
            $html .= '<span style="'.$styleCSS.'"> '.$val.'&nbsp;</span>';
        }else{
            if($fieldsInfo['showheight'] < 40){
                $html .= '<input type="text" name="'.$fieldCode.'" value="'.$val.'" class="'.$fieldCode.'" autocomplete="off" placeholder="请输入" '.$styleWH.'>'.PHP_EOL;
            }else{
                $html .= '<textarea name="'.$fieldCode.'" class="'.$fieldCode.'" autocomplete="off" placeholder="请输入" '.$styleWH.'>'.$val.'</textarea>'.PHP_EOL;
            }
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 富文本
     * User: ZhuHaili
     */
    static private function itemRichText($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? str_replace('&quot;uploads/','&quot;'.SYS_LINK.'uploads/',$essayInfo[$fieldCode]) : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        $ruleInfo = $fieldsInfo['fieldclassrule'] ? $fieldsInfo['fieldclassrule'] : $fieldsInfo['fieldrule'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $html .= '<div class="textdesc_box" '.$styleWH.'>'.PHP_EOL;
        if($fieldsInfo['banflag'] == '1'){
            $styleAdd = 'display:inline-block;border:1px solid #ddd;padding: 5px 10px;line-height:20px;background: #dfdfdf;';
            $styleWH2 = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']).$styleAdd);
            $html .= '<span style="'.$styleWH2.'"> '.$val.'&nbsp;</span>';
        }else{
            $html .= '<textarea name="' . $fieldCode . '" id="' . $fieldCode . '" class="' . $fieldCode . '" ' . $styleWH . '>' . $val . '</textarea>' . PHP_EOL;
        }
        $html .= '</div>'.PHP_EOL;
        $html .= '<i class="hint">'.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '//富文本'.PHP_EOL;
        $result['style'] .= 'var editor = new wangEditor("'.$fieldCode.'");'.PHP_EOL;
        $result['style'] .= 'editor.create("'.$ruleInfo.'");'.PHP_EOL;
        $result['style'] .= 'editor.$editorContainer.css("z-index", 10);'.PHP_EOL;
        return $result;
    }

    /**
     * Notes: 整数
     * User: ZhuHaili
     */
    static private function itemInt($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        if($fieldsInfo['banflag'] == '1'){
            $styleCSS = 'display:inline-block;width:280px;height:20px;border:1px solid #ddd;padding: 5px 10px;line-height:20px;background: #dfdfdf;';
            $html .= '<span style="'.$styleCSS.'"> '.$val.'&nbsp;</span>';
        }else {
            $html .= '<input type="number" name="' . $fieldCode . '" class="' . $fieldCode . '" value="' . $val . '" autocomplete="off" placeholder="请输入整数" ' . $styleWH . '>' . PHP_EOL;
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 货币
     * User: ZhuHaili
     */
    static private function itemMoney($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        if($fieldsInfo['banflag'] == '1'){
            $styleCSS = 'display:inline-block;width:280px;height:20px;border:1px solid #ddd;padding: 5px 10px;line-height:20px;background: #dfdfdf;';
            $html .= '<span style="'.$styleCSS.'"> '.$val.'&nbsp;</span>';
        }else {
            $html .= '<input type="text" name="' . $fieldCode . '" class="floats2 ' . $fieldCode . '" value="' . $val . '" autocomplete="off" placeholder="请输入" ' . $styleWH . '>' . PHP_EOL;
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 密码
     * User: ZhuHaili
     */
    static private function itemPassword($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        if($fieldsInfo['banflag'] == '1'){
            $styleCSS = 'display:inline-block;width:280px;height:20px;border:1px solid #ddd;padding: 5px 10px;line-height:20px;background: #dfdfdf;';
            $html .= '<span style="'.$styleCSS.'"> '.$val.'&nbsp;</span>';
        }else {
            $html .= '<input type="password" name="' . $fieldCode . '" class="' . $fieldCode . '" autocomplete="off" ' . $styleWH . '>' . PHP_EOL;
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 唯一码
     * User: ZhuHaili
     */
    static private function itemIdCode($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $ruleInfo = $fieldsInfo['fieldclassrule'] ? $fieldsInfo['fieldclassrule'] : $fieldsInfo['fieldrule'];
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : self::codeStr($ruleInfo);
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        if($fieldsInfo['banflag'] == '1'){
            $styleCSS = 'display:inline-block;width:280px;height:20px;border:1px solid #ddd;padding: 5px 10px;line-height:20px;background: #dfdfdf;';
            $html .= '<span style="'.$styleCSS.'"> '.$val.'&nbsp;</span>';
        }else {
            $html .= '<input type="text" name="' . $fieldCode . '" class="' . $fieldCode . '" value="' . $val . '" autocomplete="off" placeholder="系统自动生成不可编辑" ' . $styleWH . '>' . PHP_EOL;
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 时间日期
     * User: ZhuHaili
     */
    static private function itemDatetime($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        if($fieldsInfo['banflag'] == '1'){
            $styleCSS = 'display:inline-block;width:280px;height:20px;border:1px solid #ddd;padding: 5px 10px;line-height:20px;background: #dfdfdf;';
            $html .= '<span style="'.$styleCSS.'"> '.$val.'&nbsp;</span>';
        }else {
            $html .= '<input type="text" name="' . $fieldCode . '" id="' . $fieldCode . '" class="' . $fieldCode . '" value="' . $val . '" autocomplete="off" placeholder="请选择" ' . $styleWH . '>' . PHP_EOL;
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = 'jeDate({dateCell: "#'.$fieldCode.'",isTime: true,format: "YYYY-MM-DD hh:mm:ss"})';
        return $result;
    }

    /**
     * Notes: 省市区
     * User: ZhuHaili
     */
    static private function itemDistrict($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        if($fieldsInfo['banflag'] == '1'){
            $styleCSS = 'display:inline-block;width:280px;height:20px;border:1px solid #ddd;padding: 5px 10px;line-height:20px;background: #dfdfdf;';
            $html .= '<span style="'.$styleCSS.'"> '.$val.'&nbsp;</span>';
        }else {
            $html .= '<input type="text" name="' . $fieldCode . '" class="selectAreas ' . $fieldCode . '" value="' . $val . '" autocomplete="off" placeholder="请选择" ' . $styleWH . '>' . PHP_EOL;
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 颜色
     * User: ZhuHaili
     */
    static private function itemColor($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        if($fieldsInfo['banflag'] == '1'){
            $styleCSS = 'display:inline-block;width:280px;height:20px;border:1px solid #ddd;padding: 5px 10px;line-height:20px;background: #dfdfdf;';
            $html .= '<span style="'.$styleCSS.'"> '.$val.'&nbsp;</span>';
        }else {
            $html .= '<input type="text" name="' . $fieldCode . '" class="jscolors ' . $fieldCode . '" value="' . $val . '" autocomplete="off" placeholder="单击右侧图标打开颜色选择器" ' . $styleWH . '>' . PHP_EOL;
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 下拉选择
     * User: ZhuHaili
     */
    static private function itemSelect($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $ruleInfo = $fieldsInfo['fieldclassrule'] ? $fieldsInfo['fieldclassrule'] : $fieldsInfo['fieldrule'];
        $ruleArr = explode('|', $ruleInfo);
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $banFlag = $fieldsInfo['banflag'] == '1' ? 'disabled="disabled"' : '';
        $html .= '<select name="'.$fieldCode.'" class="'.$fieldCode.'" '.$styleWH.' '.$banFlag.'>'.PHP_EOL;
        foreach($ruleArr as $v){
            $ruleItem = explode('=', $v);
            $title = isset($ruleItem[0]) ? $ruleItem[0] : '-';
            $value = isset($ruleItem[1]) ? $ruleItem[1] : '';
            $selected = $value == $val ? 'selected="selected"' : '';
            $html .= '<option value="'.$value.'" '.$selected.'>'.$title.'</option>'.PHP_EOL;
        }
        $html .= '</select>'.PHP_EOL;
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 单选
     * User: ZhuHaili
     */
    static private function itemRadio($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $ruleInfo = $fieldsInfo['fieldclassrule'] ? $fieldsInfo['fieldclassrule'] : $fieldsInfo['fieldrule'];
        $ruleArr = explode('|', $ruleInfo);
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $banFlag = $fieldsInfo['banflag'] == '1' ? 'disabled="disabled"' : '';
        foreach($ruleArr as $v){
            $ruleItem = explode('=', $v);
            $title = isset($ruleItem[0]) ? $ruleItem[0] : '-';
            $value = isset($ruleItem[1]) ? $ruleItem[1] : '';
            $checked = $value == $val ? 'checked="checked"' : '';
            $html .= '<label class="radio"><input type="radio" value="'.$value.'" name="'.$fieldCode.'" class="'.$fieldCode.'" '.$checked.' '.$styleWH.' '.$banFlag.'>'.$title.'</label>'.PHP_EOL;
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 多选
     * User: ZhuHaili
     */
    static private function itemCheckbox($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $ruleInfo = $fieldsInfo['fieldclassrule'] ? $fieldsInfo['fieldclassrule'] : $fieldsInfo['fieldrule'];
        $ruleArr = explode('|', $ruleInfo);
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $banFlag = $fieldsInfo['banflag'] == '1' ? 'disabled="disabled"' : '';
        foreach($ruleArr as $k=>$v){
            $ruleItem = explode('=', $v);
            $title = isset($ruleItem[0]) ? $ruleItem[0] : '-';
            $value = isset($ruleItem[1]) ? $ruleItem[1] : '';
            $valArr = explode('|', $val);
            $checked = in_array($value, $valArr) ? 'checked="checked"' : '';
            $html .= '<label class="radio"><input type="checkbox" value="'.$value.'" name="'.$fieldCode.'[]" class="'.$fieldCode.'" '.$checked.' '.$styleWH.' '.$banFlag.'>'.$title.'</label>'.PHP_EOL;
            if(in_array($k,array(4,8,12,16,20,24,28,32))){
                $html .= '<br><label> &nbsp; </label>&nbsp;';
            }
        }
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes:图片裁剪个数和宽高控制计算
     * User: ZhuHaili
     * Date: 2022/9/11
     */
    static private function picCutCountWidthHeight($fieldsInfo){
        $cutW = 0;
        $cutH = 0;
        $banCount = 1;
        $ruleInfo = $fieldsInfo['fieldclassrule'] ? $fieldsInfo['fieldclassrule'] : $fieldsInfo['fieldrule'];
        if($ruleInfo){
            if(is_numeric($ruleInfo)){
                $banCount = $ruleInfo;
            }
            if(!strpos($ruleInfo,'=')){
                $ruleInfo = $banCount.'='.$ruleInfo;
            }
            if(!strpos($ruleInfo,'|')){
                $ruleInfo = $ruleInfo.'|';
            }
            $rule = explode('=', $ruleInfo);
            $banCount = intval($rule[0]) && isset($rule[1]) ? intval($rule[0]) : $banCount;
            $cutRule = isset($rule[1]) ? $rule[1] : $rule[0];
            $rules = explode('|', $cutRule);
            $cutW = intval($rules[0]) ? intval($rules[0]) : $cutW;
            $cutH = isset($rules[1]) && intval($rules[1]) ? intval($rules[1]) : $cutH;
        }
        return array('c'=>$banCount, 'w'=>$cutW, 'h'=>$cutH);
    }

    /**
     * Notes: 单图片上传
     * User: ZhuHaili
     */
    static private function itemPic($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        //裁剪控制个数和宽高
        $cutRule = self::picCutCountWidthHeight($fieldsInfo);
        $cutW = $cutRule['w'];
        $cutH = $cutRule['h'];
        $banCount = $cutRule['c'];
        //其他规则
        $fieldrule2 = isset($fieldsInfo['fieldrule2']) && $fieldsInfo['fieldrule2'] ? urlencode($fieldsInfo['fieldrule2']) : 0;
        $cutflag = isset($fieldsInfo['cutflag']) ? intval($fieldsInfo['cutflag']) : 0;
        $cuttype = isset($fieldsInfo['cuttype']) ? intval($fieldsInfo['cuttype']) : 0;
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $banFlag = $fieldsInfo['banflag'] == '1' ? 'disabled="disabled"' : '';
        $html .= '<input type="text" id="'.$fieldCode.'" name="'.$fieldCode.'" class="'.$fieldCode.'" value="'.$val.'" cut_w="'.$cutW.'" cut_h="'.$cutH.'" cut_c="'.$banCount.'" '.$banFlag.' autocomplete="off" placeholder="点击上传" '.$styleWH.'>'.PHP_EOL;
        $html .= '<i class="hint">'.PHP_EOL;
        $fileUrl = strpos($val,'http:') === false && strpos($val,'https:') === false ? OSS_HOST.$val : $val;
        $html .= '<img src="'.SYS_LINK.'admin/img/common/pic.png" img_src="'.$fileUrl.'" class="show_pic_btn"> '.PHP_EOL;
        $html .= '<a href="javascript:;" class="del_input_btn" data-id="'.$fieldCode.'">&nbsp;</a> '.PHP_EOL;
        $html .= '* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        $uploadUrl = "c_upload_base64upload/cut_w/$cutW/cut_h/$cutH/cut_c/$banCount/cut_f/$cutflag/cut_t/$cuttype/other/$fieldrule2";
        if($fieldsInfo['banflag'] != '1'){
            $result['style'] = '// 图片上传'.PHP_EOL;
            $result['style'] .= '$("#'.$fieldCode.'").on("click",function (){'.PHP_EOL;
            $result['style'] .= ' let param = [];'.PHP_EOL;
            $fileUploadUrl = SYS_URL_PATH($uploadUrl);
            $result['style'] .= ' param["zhl_upload_url"] = "'.$fileUploadUrl.'"'.PHP_EOL;
            //$result['style'] .= ' param["zhl_upload_url"] = http_url+"c_upload_base64upload/go/1"+http_fix;'.PHP_EOL;
            //$result['style'] .= ' param["zhl_upload_url"] = http_url+"c_upload_base64upload/go/1/cut_w/'.$cutW.'/cut_h/+'.$cutH.'/cut_c/1"+http_fix;'.PHP_EOL;
            $result['style'] .= ' param["zhl_upload_num"] = 1'.PHP_EOL;
            $result['style'] .= ' param["zhl_upload_size"] = 10485760'.PHP_EOL;
            $result['style'] .= ' param["zhl_upload_box"] = "#'.$fieldCode.'"'.PHP_EOL;
            $result['style'] .= ' param["zhl_upload_css"] = "zhl_upload_css_one"'.PHP_EOL;
            $result['style'] .= ' $("body").zhlUploads(param,function(e){});'.PHP_EOL;
            $result['style'] .= '});';
        }
        return $result;
    }

    /**
     * Notes: 多图片上传
     * User: ZhuHaili
     */
    static private function itemPicMore($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        //裁剪控制个数和宽高
        $cutRule = self::picCutCountWidthHeight($fieldsInfo);
        $cutW = $cutRule['w'];
        $cutH = $cutRule['h'];
        $banCount = $cutRule['c'];
        //其他规则
        $fieldrule2 = isset($fieldsInfo['fieldrule2']) && $fieldsInfo['fieldrule2'] ? urlencode($fieldsInfo['fieldrule2']) : 0;
        $cutflag = isset($fieldsInfo['cutflag']) ? intval($fieldsInfo['cutflag']) : 0;
        $cuttype = isset($fieldsInfo['cuttype']) ? intval($fieldsInfo['cuttype']) : 0;
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $banFlag = $fieldsInfo['banflag'] == '1' ? 'disabled="disabled"' : '';
        $html .= '<input type="text" id="'.$fieldCode.'" name="'.$fieldCode.'" class="'.$fieldCode.'" cut_w="'.$cutW.'" cut_h="'.$cutH.'" cut_c="'.$banCount.'" value="'.$val.'" '.$banFlag.' autocomplete="off" placeholder="点击上传" '.$styleWH.'>'.PHP_EOL;
        $html .= '<i class="hint">'.PHP_EOL;
        $imgPaths = explode('|', $val);
        foreach($imgPaths as $img){
            $fileUrl = strpos($img,'http:') === false && strpos($img,'https:') === false ? OSS_HOST.$img : $img;
            $html .= '<img src="'.SYS_LINK.'admin/img/common/pic.png" img_src="'.$fileUrl.'" class="show_pic_btn"> '.PHP_EOL;
        }
        $html .= '<a href="javascript:;" class="del_input_btn" data-id="'.$fieldCode.'">&nbsp;</a> '.PHP_EOL;
        $html .= '* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        $uploadUrl = "c_upload_base64upload/cut_w/$cutW/cut_h/$cutH/cut_c/$banCount/cut_f/$cutflag/cut_t/$cuttype/other/$fieldrule2";
        if($fieldsInfo['banflag'] != '1'){
            $result['style'] = '// 多图片上传'.PHP_EOL;
            $result['style'] .= '$("#'.$fieldCode.'").on("click",function (){'.PHP_EOL;
            $result['style'] .= ' let param = [];'.PHP_EOL;
            $fileUploadUrl = SYS_URL_PATH($uploadUrl);
            $result['style'] .= ' param["zhl_upload_url"] = "'.$fileUploadUrl.'"'.PHP_EOL;
            $result['style'] .= ' param["zhl_upload_num"] = '.$banCount.PHP_EOL;
            $result['style'] .= ' param["zhl_upload_size"] = 10485760'.PHP_EOL;
            $result['style'] .= ' param["zhl_upload_box"] = "#'.$fieldCode.'"'.PHP_EOL;
            $result['style'] .= ' param["zhl_upload_css"] = "zhl_upload_css_more"'.PHP_EOL;
            $result['style'] .= ' $("body").zhlUploads(param,function(e){});'.PHP_EOL;
            $result['style'] .= '});';
        }
        return $result;
    }

    /**
     * Notes: 单文件上传
     * User: ZhuHaili
     */
    static private function itemFile($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $banFlag = $fieldsInfo['banflag'] == '1' ? 'disabled="disabled"' : '';
        $fileBtnStyle = $fieldsInfo['banflag'] != '1' ? 'iframe_upload' : '';
        $html .= '<input type="text" id="'.$fieldCode.'" name="'.$fieldCode.'" class="'.$fileBtnStyle.'" cut_c="1" value="'.$val.'" '.$banFlag.' autocomplete="off" placeholder="" '.$styleWH.'>'.PHP_EOL;
        $html .= '<i class="hint">'.PHP_EOL;
        $html .= '<a href="javascript:;" class="upload_input_btn" ></a> '.PHP_EOL;
        $fileUrl = strpos($val,'http:') === false && strpos($val,'https:') === false ? OSS_HOST.$val : $val;
        $html .= '<a href="'.$fileUrl.'" class="dowload_input_btn" target="_blank"></a> '.PHP_EOL;
        $html .= '<a href="javascript:;" class="del_input_btn" data-id="'.$fieldCode.'">&nbsp;</a> '.PHP_EOL;
        $html .= '* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 多文件上传
     * User: ZhuHaili
     */
    static private function itemFileMore($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        $ruleInfo = $fieldsInfo['fieldclassrule'] ? $fieldsInfo['fieldclassrule'] : $fieldsInfo['fieldrule'];
        $banCount = 1;
        if(is_numeric($ruleInfo)){
            $banCount = $ruleInfo;
        }
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $banFlag = $fieldsInfo['banflag'] == '1' ? 'disabled="disabled"' : '';
        $fileBtnStyle = $fieldsInfo['banflag'] != '1' ? 'iframe_upload' : '';
        $html .= '<input type="text" id="'.$fieldCode.'" name="'.$fieldCode.'" class="'.$fileBtnStyle.'" cut_c="'.$banCount.'" value="'.$val.'" '.$banFlag.' autocomplete="off" placeholder="点击上传" '.$styleWH.'>'.PHP_EOL;
        $html .= '<i class="hint">'.PHP_EOL;
        $paths = explode('|', $val);
        foreach($paths as $file){
            $fileUrl = strpos($file,'http:') === false && strpos($file,'https:') === false ? OSS_HOST.$file : $file;
            $html .= '<a href="'.$fileUrl.'" class="dowload_input_btn" target="_blank"></a> '.PHP_EOL;
        }
        $html .= '<a href="javascript:;" class="del_input_btn" data-id="'.$fieldCode.'">&nbsp;</a> '.PHP_EOL;
        $html .= '* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 图片上传裁剪
     * User: ZhuHaili
     */
    static private function itemImgCut($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        $ruleInfo = $fieldsInfo['fieldclassrule'] ? $fieldsInfo['fieldclassrule'] : $fieldsInfo['fieldrule'];
        $cutW = 200;
        $cutH = 200;
        if($ruleInfo){
            $rules = explode('|', $ruleInfo);
            $cutW = intval($rules[0]) ? intval($rules[0]) : $cutW;
            $cutH = intval($rules[1]) ? intval($rules[1]) : $cutH;
        }
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $banFlag = $fieldsInfo['banflag'] == '1' ? 'disabled="disabled"' : '';
        $fileBtnStyle = $fieldsInfo['banflag'] != '1' ? 'imgCutInputBox' : '';
        $html .= '<input type="text" id="'.$fieldCode.'" name="'.$fieldCode.'" class="'.$fileBtnStyle.'" cut_w="'.$cutW.'" cut_h="'.$cutH.'" value="'.$val.'" '.$banFlag.' autocomplete="off" placeholder="点击上传" '.$styleWH.'>'.PHP_EOL;
        $html .= '<i class="hint">'.PHP_EOL;
        $fileUrl = strpos($val,'http:') === false && strpos($val,'https:') === false ? OSS_HOST.$val : $val;
        $html .= '<img src="'.SYS_LINK.'admin/img/common/pic.png" img_src="'.$fileUrl.'" class="show_pic_btn"> '.PHP_EOL;
        $html .= '<a href="javascript:;" class="del_input_btn" data-id="'.$fieldCode.'">&nbsp;</a> '.PHP_EOL;
        $html .= '* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }

    /**
     * Notes: 自定义字段模版-按钮
     * User: ZhuHaili
     */
    static private function itemFieldTmpl($fieldsInfo, $essayInfo){
        // 样式
        $br = self::itemTitleBr($fieldsInfo['showheight']);
        $styleWH = self::itemStyle(self::itemSize($fieldsInfo['showwidth'], $fieldsInfo['showheight']));
        // 字段属性
        $fieldCode = $fieldsInfo['fieldcode'];
        $val = isset($essayInfo[$fieldCode]) ? $essayInfo[$fieldCode] : '';
        $hint = $fieldsInfo['fielddesc'] ? $fieldsInfo['fielddesc'] : $fieldsInfo['fieldhint'];
        // 字段html
        $html = '<div class="form_item">'.PHP_EOL;
        $html .= '<label>'.$fieldsInfo['fieldname'].$br.'</label>'.PHP_EOL;
        $html .= '<button class="btn_base field_info_list '.$fieldCode.'" data-tmpid="'.$val.'" data-field="'.$fieldCode.'">内容</button>';
        $html .= '<i class="hint">* '.$hint.$br.'</i>'.PHP_EOL;
        $html .= '</div>'.PHP_EOL;
        // 结果集
        $result['html'] = $html;
        $result['style'] = '';
        return $result;
    }
}
